#include <iostream>
#include <cstdio>

using namespace std;

#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1

const int maxn = 200001;

int n, M;

int maxs[maxn << 2];

void PushUp(int rt) {
	maxs[rt] = max(maxs[rt << 1] , maxs[rt << 1 | 1]);
}

void build(int l, int r, int rt) {
	if (l == r) {
		scanf("%d", &maxs[rt]);
		return;
	}
	int m = (l + r) >> 1;
	build(lson);
	build(rson);
	PushUp(rt);
}

void update(int p, int add, int l, int r, int rt) {
	if (l == r) {
		maxs[rt] = add;
		return;
	}
	int m = (l + r) >> 1;
	if (p <= m) update(p, add, lson);
	else update(p, add, rson);
	PushUp(rt);
}

int query(int L, int R, int l, int r, int rt) {
	if (L <= l && r <= R) {
		return maxs[rt];
	}
	int m = (l + r) >> 1;
	int ret = 0;
	if (L <= m) ret = max(ret, query(L, R, lson));
	if (R > m) ret = max(ret, query(L, R, rson));
	return ret;
}

int main() {

	while(scanf("%d%d", &n, &M) != EOF) {
		build(1, n, 1);
		for (int i = 0; i < M; i++) {
			char op;
			getchar();
			scanf("%c", &op);
			int a, b;
			scanf("%d%d", &a, &b);
			if (op == 'Q') cout << query(a, b, 1, n, 1) << endl;
			else update(a, b, 1, n, 1);
		}
	}
}
